#include "Button.h"
#include "mock/ArduinoMock.h"
#include "mock/MessageRouterMock.h"
#include "mock/LoggerMock.h"
using ::testing::_;
using ::testing::Return;
using ::testing::AnyNumber;

TEST(debounceCheck, debounce){
	ArduinoMock arduino;
	MessageRouterMock router;
	LoggerMock log;
	int pin = 11;

	EXPECT_CALL(arduino, dWrite(pin, arduino.HIGHVAL()));
	EXPECT_CALL(arduino, pin(pin, arduino.IN()));
	Button button(arduino, router, "kitchen", log, pin, 50);

	EXPECT_CALL(arduino, dRead(pin))
		.WillOnce(Return(1));
	button.tick(0);

	EXPECT_CALL(arduino, dRead(pin))
		.WillOnce(Return(0));
	button.tick(1);

	EXPECT_CALL(arduino, dRead(pin))
		.WillOnce(Return(1));
	button.tick(10);

	EXPECT_CALL(arduino, dRead(pin))
		.WillOnce(Return(0));
	button.tick(pin);

	EXPECT_CALL(router, postMessage(_, String("{\"event\":\"button\", \"id\":\"kitchen\", \"state\":\"on\"}")))
		.Times(1);
	EXPECT_CALL(arduino, dRead(pin))
		.WillOnce(Return(0));
	button.tick(62);
}